require('../css/commCss/normalize.css')
require('../css/commCss/reset.css')
require('../css/commCss/property.css')
require('../css/commCss/basic.css')


// 获取swiper
require('../lib/swiper/swiper-bundle.css')
const Swiper= require('../lib/swiper/swiper-bundle')

// 字体
require('../lib/iconfont/iconfont.css')

// 确认验证码是否正确
const axios=require('axios')

// weui-轻提示
require('weui')
const weui= require('weui.js')

// 公用尾部导航
const util=require('../lib/util/util')

require('../css/home.less')

const rank=document.querySelector('#rank')
const punchDay=document.querySelector('#punchDay')
const punchToday=document.querySelector('#punchToday')
const badgeNum=document.querySelector('#badgeNum')

window.addEventListener('DOMContentLoaded',function(){
  let listThird=document.querySelector('#listThird')
  let listFourth=document.querySelector('#listFourth')

    var mySwiper = new Swiper('.swiper',{
      loop : true,
      autoplay:{
        delay:3000,
        disableOnInteraction:false
      },
      pagination: {
      el: '.swiper-pagination',
      clickable :true,
      },
      navigation: {
          nextEl: '.swiper-button-next',
          prevEl: '.swiper-button-prev',
      },
    })

    // 值
    axios.get('http://139.9.177.51:8099/headPageInfo',{
      params:{
        userId:localStorage.getItem('userId')
      }
    }).then(function(res){
      rank.textContent=res.data.data.rank
      punchDay.textContent=res.data.data.punchIn
      badgeNum.textContent=res.data.data.insigniaNum

      res.data.data.isPunch==='true'? punchToday.textContent='已打卡' : punchToday.textContent='打卡成功'
    })

    // 今日打卡
    punchToday.addEventListener('click',function(){
      axios.get('http://139.9.177.51:8099/clockIn',{
        params:{
          userId:localStorage.getItem('userId')
        }
      }).then(function(res){
        if(res.data.status===0){
          punchDay.textContent++
          punchToday.textContent='已打卡'
          weui.toast('打卡成功',1000)
        }else{
          punchToday.textContent='已打卡'
          weui.toast('已打卡',1000)
        }
      })
    })

    util.commonFoot('home')

    listThird.addEventListener('click',function(){
      location.href='./short-part.html'
    })

    listFourth.addEventListener('click',function(){
      location.href='./countdown.html'
    })
})